package com.mvc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mvc.dao.EntityDao;
import com.mvc.entity.Student;

@Service
public class StudentService {
	@Autowired
	private EntityDao entityDao;

	@Transactional
	public List<Object> getstudList() {

		StringBuffer sbf = new StringBuffer();
		sbf.append("select a from ").append(Student.class.getSimpleName()).append(" a ");
		List<Object> list = entityDao.createQuery(sbf.toString());
		return list;
	}

	public void save(Student student) {
		entityDao.save(student);
	}

	public void delete(Object obj) {
		entityDao.delete(obj);
	}

	public void update(Student student) {
		entityDao.update(student);
	}

	public Student selectById(Integer id) {
		StringBuffer sb = new StringBuffer();
		sb.append("select a from ").append(Student.class.getSimpleName()).append(" a ");
		sb.append("where a.id=" + id + "");
		//return (Student) entityDao.createQuery(sb.toString()).get(0);
		 return entityDao.selectById(id);
	}
}
